﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/BaseMaster/DetailPages.Master" AutoEventWireup="true" CodeBehind="UserManageDetail.aspx.cs" Inherits="Liu_Project.Web.Admin.Pages.Personal.EntUser.UserManageDetail" %>

<asp:Content ID="Content1" ContentPlaceHolderID="DetailTitle" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="DetailHead" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="DetailContent" runat="server">
    <div class="layui-card">
        <form class="layui-form" lay-filter="userForm" style="padding: 20px;">
            <div class="layui-form-item">
                <label class="layui-form-label">用户编号</label>
                <div class="layui-input-block">
                    <input type="text" name="UserNo" placeholder="请输入用户编号" lay-verify="required|userno" lay-vertype="tips" autocomplete="off" class="layui-input" maxlength="10">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户名称</label>
                <div class="layui-input-block">
                    <input type="text" name="UserName" placeholder="请输入用户名称" lay-verify="required|username" lay-vertype="tips" autocomplete="off" class="layui-input" maxlength="8">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">角色</label>
                <div class="layui-input-block">
                    <div id="role" class="xm-select-demo"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="IsVisiable" lay-skin="switch" lay-text="正常|禁用" checked>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="Password" placeholder="请输入密码" lay-verify="pass" lay-vertype="tips" autocomplete="new-password" class="layui-input" maxlength="12">
                </div>
                <div class="layui-form-mid layui-word-aux pwd">不更改密码,则不需填写</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-inline">
                    <input type="password" id="newPwd" placeholder="请输入确认密码" lay-verify="newpass" lay-vertype="tips" autocomplete="new-password" class="layui-input" maxlength="12">
                </div>
                <div class="layui-form-mid layui-word-aux pwd">同上</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机号</label>
                <div class="layui-input-block">
                    <input type="text" name="Phone" placeholder="请输入手机号" lay-verify="required|phone|number" lay-vertype="tips" autocomplete="off" class="layui-input" maxlength="11">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input type="text" name="Email" placeholder="请输入邮箱" lay-verify="required|email" lay-vertype="tips" autocomplete="off" class="layui-input" maxlength="20">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit lay-filter="*">保存</button>
                    <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
                </div>
            </div>
        </form>
    </div>


</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="DetailScript" runat="server">
    <script src="/javascripts/lib/extend/xmSelect/xm-select.js"></script>
    <script>
        var CurrData = {};

        var roleSelect = xmSelect.render({
            el: '#role',
            filterable: true,
            autoRow: true,
            toolbar: {
                show: true,
            },
            data: []
        })

        function setData(event, data) {
            CurrData._state = event;
            if (event == "Add") {
                $("input[name='Password']").attr("lay-verify", "required|pass");
                $("#newPwd").attr("lay-verify", "required|newpass");
                $(".pwd").hide();
            }
            if (event == "Edit") {
                CurrData = objDeepCopy(data);
                CurrData._state = event;
                layui.form.val("userForm", CurrData);
            }

            GetObjectInfoFunction_Async("Admin/Handler/Personal/EntRoleHand.ashx", { "act": "GetUserRoleList", "Id": CurrData.UserId }, function (result) {
                if (result.IsSuccess) {
                    if (result.data.length == 0)
                        return;
                    roleSelect.update({
                        data: result.data
                    })
                }
            })
        }

        layui.form.verify({
            userno: function (value, item) {
                if (!new RegExp(/^[0-9a-zA-Z]*$/g).test(value)) {
                    return '只能是字母，数字或字母数字组合';
                }
            },
            username: function (value, item) {//value：表单的值、item：表单的DOM对象
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '不能有特殊字符';
                }
                if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                    return '首尾不能出现下划线\'_\'';
                }
                if (/^\d+\d+\d$/.test(value)) {
                    return '不能全为数字';
                }
            }, pass: function (value, item) {
                if (value.length == 0)
                    return;
                if (!new RegExp(/^[\S]{6,12}$/).test(value)) {
                    return '密码必须6到12位，且不能出现空格';
                }
            }, newpass: function (value) {
                var pvalue = $("input[name='Password']").val();
                if (pvalue.length == 0)
                    return;
                if (!(value.length >= 6) || value.length > 12) {
                    return "密码必须6到12位";
                }
                if (pvalue != value) {
                    return "两次输入的密码不相同";
                };
            }, phone: function (value) {
                let valid_rule = /^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$/;
                if (!valid_rule.test(value)) {
                    return "手机号码格式有误";
                }
            }
            //, phone: function (value) {
            //    let valid_rule = /^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$/;
            //    if (!valid_rule.test(value)) {
            //        return "手机号码格式有误";
            //    }
            //}
        });

        layui.form.on('submit(*)', function (data) {
            if (data.field.IsVisiable == "on")
                data.field.IsVisiable = 1;
            else
                data.field.IsVisiable = 0;
            UpdateJson(CurrData, data.field);

            let roleData = roleSelect.getValue();
            if (StringIsNullOrEmpty(roleData)) {
                layer.msg('请选择角色后,再操作.');
                roleSelect.warning('red', true);
                return false;
            }
            top.layer.load(1);
            GetObjectInfoFunction_Async("Admin/Handler/BaseHand/UserRoleHand.ashx", {
                "act": "Save", "_state": CurrData._state, "Data": JSON.stringify(CurrData), "roleData": JSON.stringify(roleData)
            }, function (result) {
                if (result.IsSuccess) {
                    if (result.data.length == 0)
                        return;
                    top.layer.msg('保存成功');
                    close();
                }
            })

            return false;
        });

        $("#cancel").click(function () {
            close();
        });

        function close() {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        }

    </script>
</asp:Content>
